# use normal make for this Makefile
#
# Makefile for building user programs to run on top of Nachos
#
# Several things to be aware of:
#
#    Nachos assumes that the location of the program startup routine (the
# 	location the kernel jumps to when the program initially starts up)
#       is at location 0.  This means: start.o must be the first .o passed 
# 	to ld, in order for the routine "Start" to be loaded at location 0
#

# If you are running on SunOS 5.x machines, uncomment the next line
GCCDIR = /auto/home-scf-22/csci402/testgnu/decstation-ultrix/bin/
LDFLAGS = -T newscript -N
ASFLAGS = -mips1
CPPFLAGS = $(INCDIR)

# if you aren't cross-compiling:
# GCCDIR =
# LDFLAGS = -N -T 0
# ASFLAGS =
# CPPFLAGS = -P $(INCDIR)


CC = $(GCCDIR)gcc
AS = $(GCCDIR)as
LD = $(GCCDIR)ld
CPP = $(GCCDIR)cpp

INCDIR =-I../userprog -I../threads
CFLAGS = -G 0 -c $(INCDIR)

all: halt lock condition matmult sort testfiles theater part2test part1test execsample problem2 part3

start.o: start.s ../userprog/syscall.h
	$(CPP) $(CPPFLAGS) start.s > strt.s
	$(AS) $(ASFLAGS) -o start.o strt.s
	rm strt.s

halt.o: halt.c
	$(CC) $(CFLAGS) -c halt.c
halt: halt.o start.o
	$(LD) $(LDFLAGS) start.o halt.o -o halt.coff
	../bin/coff2noff halt.coff halt

lock.o: lock.c
	$(CC) $(CFLAGS) -c lock.c
lock: lock.o start.o
	$(LD) $(LDFLAGS) start.o lock.o -o lock.coff
	../bin/coff2noff lock.coff lock

condition.o: condition.c
	$(CC) $(CFLAGS) -c condition.c
condition: condition.o start.o
	$(LD) $(LDFLAGS) start.o condition.o -o condition.coff
	../bin/coff2noff condition.coff condition 

sort.o: sort.c
	$(CC) $(CFLAGS) -c sort.c
sort: sort.o start.o
	$(LD) $(LDFLAGS) start.o sort.o -o sort.coff
	../bin/coff2noff sort.coff sort

matmult.o: matmult.c
	$(CC) $(CFLAGS) -c matmult.c
matmult: matmult.o start.o
	$(LD) $(LDFLAGS) start.o matmult.o -o matmult.coff
	../bin/coff2noff matmult.coff matmult

testfiles.o: testfiles.c
	$(CC) $(CFLAGS) -c testfiles.c
testfiles: testfiles.o start.o
	$(LD) $(LDFLAGS) start.o testfiles.o -o testfiles.coff
	../bin/coff2noff testfiles.coff testfiles
	
theater.o: theater.c
	$(CC) $(CFLAGS) -c theater.c
theater: theater.o start.o
	$(LD) $(LDFLAGS) start.o theater.o -o theater.coff
	../bin/coff2noff theater.coff theater
	
part2test.o: part2test.c
	$(CC) $(CFLAGS) -c part2test.c
part2test: part2test.o start.o
	$(LD) $(LDFLAGS) start.o part2test.o -o part2test.coff
	../bin/coff2noff part2test.coff part2test
	
part1test.o: part1test.c
	$(CC) $(CFLAGS) -c part1test.c
part1test: part1test.o start.o
	$(LD) $(LDFLAGS) start.o part1test.o -o part1test.coff
	../bin/coff2noff part1test.coff part1test

execsample.o: execsample.c
	$(CC) $(CFLAGS) -c execsample.c
execsample: execsample.o start.o
	$(LD) $(LDFLAGS) start.o execsample.o -o execsample.coff
	../bin/coff2noff execsample.coff execsample
part3.o: part3.c
	$(CC) $(CFLAGS) -c part3.c
part3: part3.o start.o
	$(LD) $(LDFLAGS) start.o part3.o -o part3.coff
	../bin/coff2noff part3.coff part3

problem2.o: problem2.c
	$(CC) $(CFLAGS) -c problem2.c
problem2: problem2.o start.o
	$(LD) $(LDFLAGS) start.o problem2.o -o problem2.coff
	../bin/coff2noff problem2.coff problem2

clean:
	rm -f *.o *.coff
